package com.autism.day05;

import javafx.print.Collation;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

/**
 * 斗地主
 * 1.准备牌
 * 2.洗牌
 * 3.发牌
 * 4.看牌
 */
public class FightLandlord {
    public static void main(String[] args) {

        //1.准备牌，定义一个Arraylist,泛型使用String
        HashMap<Integer, String> poker = new HashMap<>();
        //存储牌的索引
        ArrayList<Integer> pokerIndex = new ArrayList<>();

        //定义两个数组存储花色和序号
        String[] colors = {"♥", "♠", "♦", "♣"};
        String[] numbers = {"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};

        int index = 0;

        poker.put(index, "大王");
        pokerIndex.add(index++);

        poker.put(index, "小王");
        pokerIndex.add(index++);

        //组装牌
        for (String number : numbers) {
            for (String color : colors) {
                //放入poker中
                poker.put(index, color + number);
                pokerIndex.add(index++);
            }
        }
        //2.洗牌，使用collection中的shuffle方法
        Collections.shuffle(pokerIndex);

        //3.发牌，定义四个集合存储三个玩家和底牌
        ArrayList<Integer> playerA = new ArrayList();
        ArrayList<Integer> playerB = new ArrayList();
        ArrayList<Integer> playerC = new ArrayList();
        ArrayList<Integer> remainCard = new ArrayList();

        for (int i = 0; i < pokerIndex.size(); i++) {
            Integer pIndex = pokerIndex.get(i);
            if (i >= 51) {
                remainCard.add(pIndex);
            } else {
                switch (i % 3) {
                    case 0:
                        playerA.add(pIndex);
                        break;
                    case 1:
                        playerB.add(pIndex);
                        break;
                    case 2:
                        playerC.add(pIndex);
                        break;
                    default:
                        break;
                }
            }
        }

        //排序
        Collections.sort(playerA);
        Collections.sort(playerB);
        Collections.sort(playerC);
        Collections.sort(remainCard);

        //4.看牌
        SortCard("玩家A",poker,playerA);
        SortCard("玩家B",poker,playerB);
        SortCard("玩家C",poker,playerC);
        SortCard("底牌",poker,remainCard);
    }

    /*
     *
     */
    public static void SortCard(String player, HashMap<Integer, String> poker, ArrayList<Integer> list) {
        System.out.print(player+"=>");
        for (Integer index : list) {
            String value = poker.get(index);
            System.out.print(value + " ");
        }
        System.out.println();
    }
}
